package com.whsxt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whsxt.domain.IndexImg;
import com.whsxt.service.IndexImgService;
import com.whsxt.vo.IndexImgVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-03-18 13:58
 * @Description:
 */
@RestController
@RequestMapping("/admin/indexImg")
@Api(tags = "轮播图管理")
public class IndexImgController {


    @Autowired
    private IndexImgService indexImgService;


    @GetMapping("/page")
    @ApiOperation(value = "分页查询轮播图")
    public ResponseEntity<Page<IndexImg>> indexImgPage(Page<IndexImg> page, IndexImg indexImg) {
        Page<IndexImg> imgPage = indexImgService.findIndexImgPage(page, indexImg);
        return ResponseEntity.ok(imgPage);
    }


    @PostMapping
    @ApiOperation(value = "新增轮播图")
    public ResponseEntity<Void> addIndexImg(@RequestBody IndexImg indexImg) {
        indexImgService.save(indexImg);
        return ResponseEntity.ok().build();
    }


    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据id查询轮播图")
    public ResponseEntity<IndexImg> getIndexImgInfo(@PathVariable Long id) {
        IndexImg indexImg = indexImgService.findIndexImgById(id);
        return ResponseEntity.ok(indexImg);
    }


    // -----------------前台

    /**
     * 微信小程序的性能比较差
     * 基本知识：前台代码的大小要小于  4M
     * http请求的时候，处理的数据包不能过大，专门封装对象
     *
     *
     *
     *
     *
     */


    /**
     * @return
     */
    @GetMapping("/indexImgs")
    @ApiOperation(value = "加载前台轮播图接口")
    public ResponseEntity<List<IndexImgVo>> loadFrontIndexImg() {
        List<IndexImgVo> list = indexImgService.findFrontIndexImg();
        return ResponseEntity.ok(list);
    }


}
